Read File line by line with Shell Script (bash)
entro | March 28, 2007I realize this is a very basic issue, but when searching online I found a dearth of information regarding reading a text file line by line using a shell script. So below I have included the basic code you need.
#!/bin/bash #### skeleton code for reading a file line by line ## fill variable "thefile" with the name and path of the file you want to read line by line thefile=/home/var/nameoffileyouwanttoprocess ## the loop below pipes the output of the file into a variable ($line) line by line cat $thefile | while read line do echo $line #placeholder command to make sure everything is groovy done
Hopefully this helps some people!
thanks for the code dude.
shell scripts rock!
You’re my hero! After two hours of banging my head against the wall, I stumbled across your solution, and it works! Every other solution I tried kept going word-by-word.
thx
Simple script. It works! Thanks.
[…] a Perl-based tool called split-logfile. My savage ignorance of Perl led me to look at bash in “Read File line by line with Shell Scriptâ€â€”which turned out to be hopeless slow for large Web logs. So some person named “hans†at […]
Absolutely helpful!!!! Thank you SOOOOO much! Simply brilliant!
Thanks! Exactly what I was looking for!
thanks that was really helpful!
Thanks a lot!!!!!!!!!!!!!
great stuff!!! useful indeed!
Wow… I feel like an idiot. Was trying to get something JUST LIKE THIS and I couldn’t because my edumacashun is fail. This helped me tremendously.
Thanks a lot , you saved me man 😉
I was looking for this code with explaination from a long time. Thanks. Really helpful.